
function inverseSkill(row, id) {
	$.ajax({
		url:"admin/AdminTools",
		data:{"command": "inverseSkill", "id": id},
		type:"post",
		success:function() {
			oldValue = document.getElementById("isAvailable" + row).innerHTML;
			if(oldValue == "yes") {
				document.getElementById("isAvailable" + row).innerHTML = "no";
			} else {
				document.getElementById("isAvailable" + row).innerHTML = "yes";
			}
		},
		error:function(xhr, ajaxOptions, thrownError) {
			alert("Error adding skill:\n" + xhr.responseText);
		}
	});
}

function addSkill() {
	var skill = document.getElementById("skillName").value;
	$.ajax({
		url:"admin/AdminTools",
		data:{"command": "addSkill", "skillName": skill},
		type:"post",
		success:function(text) {
			var table = document.getElementById("adminTable");
			var row = table.insertRow(-1);
			var cell = row.insertCell(0);
			cell.innerHTML = text;
			cell = row.insertCell(1);
			cell.innerHTML = skill;
			cell = row.insertCell(2);
			cell.innerHTML = "yes";
			cell = row.insertCell(3);
			cell.innerHTML = "<input type=\"button\" class=\"regularButton\" value=\"inverse\" id=\"inverse" + row.rowIndex +
			"\" onclick=\"inverse(" + row.rowIndex + ", " + text + ")\"></input>";
			document.getElementById("skillName").value = "";
		},
		error:function(xhr, ajaxOptions, thrownError) {
			alert("Error adding skill:\n" + xhr.responseText);
		}
	});
}

function delMission(row, id) {
	$.ajax({
		url:"AdminTools",
		data:{"command": "deleteMission", "id": id},
		type:"post",
		success:function() {
			document.getElementById("adminTable").deleteRow(row);
		},
		error:function(xhr, ajaxOptions, thrownError) {
			alert("Error adding skill:\n" + xhr.responseText);
		}
	});
}

function delTeam(row, username) {
	$.ajax({
		url:"AdminTools",
		data:{"command": "deleteUser", "username": username},
		type:"post",
		success:function() {
			document.getElementById("adminTable").deleteRow(row);
		},
		error:function(xhr, ajaxOptions, thrownError) {
			alert("Error adding skill:\n" + xhr.responseText);
		}
	});
}

function delUser(row, username) {
	$.ajax({
		url:"admin/AdminTools",
		data:{"command": "deleteUser", "username": username},
		type:"post",
		success:function() {
			document.getElementById("adminTable").deleteRow(row);
		},
		error:function(xhr, ajaxOptions, thrownError) {
			alert("Error adding skill:\n" + xhr.responseText);
		}
	});
}

function loadAdminContent(url) {
	$.ajax({
		url: url,
		success: function(data) {
			$("#admincontent").html(data);
		}
	});
}